// $Id: inform_xml.c,v 1.1.1.1 2012/02/17 03:45:26 hzheng Exp $

#include "log.h"
#include "data_xml.h"

#include "inform_xml.h"
#include "amspub.h"

int evcpe_inform_to_xml(struct evcpe_inform *method, struct evbuffer *buffer)
{
	int rc;
	char ParameterKey[124] = {0};

	tapiext_get(PATH_OBJ_TR069"ParameterKey", ParameterKey);

	evcpe_debug(__func__, "marshaling inform");

	if ((rc = evcpe_device_id_to_xml(&method->device_id, "DeviceId", buffer)))
		goto finally;
	if ((rc = evcpe_event_list_to_xml(&method->event, "Event", buffer)))
		goto finally;
	if ((rc = evcpe_xml_add_int(buffer,
			"MaxEnvelopes", method->max_envelopes)))
		goto finally;
	if ((rc = evcpe_xml_add_string(buffer,
			"CurrentTime", method->current_time)))
		goto finally;
	if ((rc = evcpe_xml_add_int(buffer,
			"RetryCount", method->retry_count)))
		goto finally;
	if ((rc = evcpe_param_value_list_to_xml(&method->parameter_list,
			"ParameterList", buffer)))
		goto finally;
	if (strlen(ParameterKey))
	{
		evcpe_warn(__func__, "inform ParameterKey=%s", ParameterKey);
		rc = evcpe_xml_add_string(buffer, "ParameterKey", ParameterKey);
		tapiext_sset(PATH_OBJ_TR069"ParameterKey", "");
		if(rc)
			goto finally;
	}


finally:
	return rc;
}
